package com.xuecheng.content.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.content.mapper.CourseTeacherMapper;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.impl.CourseTeacherServiceImpl;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 26455
 * @version 1.0
 * @description TODO
 * @date 2023/2/9 10:33
 */
@Slf4j
@Api(value = "课程教师管理接口", tags = "课程教师管理接口")
@RestController
@RequestMapping("/courseTeacher")
public class CourseTeacherController {

    @Autowired
    private CourseTeacherServiceImpl courseTeacherService;

    @GetMapping("/list/{id}")
    public List<CourseTeacher> list(@PathVariable Long id) {
        LambdaQueryWrapper<CourseTeacher> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CourseTeacher::getCourseId, id);
        List<CourseTeacher> list = courseTeacherService.list(queryWrapper);
        return list;
    }

    @PostMapping()
    public void add(@RequestBody CourseTeacher courseTeacher) {
        courseTeacherService.saveOrUpdate(courseTeacher);
    }

    @DeleteMapping("/course/{courseId}/{id}")
    public void delete(@PathVariable Long courseId, @PathVariable Long id) {
        courseTeacherService.removeById(id);
    }
}
